<?php
namespace My\Model;

use Utuo\UtuoModel;

class DistributionShopPackageModel extends UtuoModel {
    
    const PACKAGE_TYPE_UPDATE = 1; // 代理商升级套餐 
    const PACKAGE_TYPE_STOCK = 2;  // 代理商进货

	public static $packageTypes = array(
		'1' => '代理商升级套餐',
	    '2' => '代理商进货套餐',
	);
	
	public static $status = array(
		'0' => '下架',
		'1' => '上架',
	);
	
	protected $_auto = array(
		array('create_time', 'time', self::MODEL_INSERT, 'function'),
	    array('shipping_config', 'getShippingConfig', self::MODEL_BOTH, 'callback'),
	    array('config', 'getConfig', self::MODEL_BOTH, 'callback'),
	);
	
	protected $_validate = array(
		array('name', 'require', '请输入套餐名称', self::MUST_VALIDATE, '', self::MODEL_BOTH),
		array('image', 'require', '请上传套餐封面图片', self::MUST_VALIDATE, '', self::MODEL_BOTH),
		array('type', 'require', '请选择套餐类型', self::MUST_VALIDATE, '', self::MODEL_BOTH),
	);
	
	/**
	 * 获得运送配置
	 * @return Ambigous <string, mixed>
	 */
	public function getShippingConfig() {
	    $shipping_method = "";
	    if ( isset($_REQUEST['shipping_config']) ) {
	        $shipping_method = I("shipping_config", "");
	        if ( is_array($shipping_method) ) {
	            $shipping_method = serialize($shipping_method);
	        }
	    }
	    return $shipping_method;
	}
	
	/**
	 * 获得运送配置
	 * @return Ambigous <string, mixed>
	 */
	public function getConfig() {
	    $config = "";
	    if ( isset($_REQUEST['config']) ) {
	        $config = I("config", "");
	        if ( is_array($config) ) {
	            $config = serialize($config);
	        }
	    }
	    return $config;
	}
	
}